/* * Copyright (C) 2021 Huawei Device Co., Ltd.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhouyou.http.model.utils;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.aafwk.ability.delegation.IAbilityDelegator;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

import static com.zhouyou.http.demo.constant.AppConstant.*;
import static com.zhouyou.http.demo.constant.AppConstant.XPATH1;
import static org.junit.Assert.*;

public class FileUtilsTest {
    private static IAbilityDelegator sAbilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();

    @Test
    public void getFileName() {
        StringBuffer sb = new StringBuffer(SCHEMA).append(XIAOMI).append(XPATH).append(XPATH1);
        String fileName = FileUtils.getFileName(sb.toString());
        System.out.println(fileName);
        assertTrue("fileName is downloading url", !fileName.isEmpty());
    }

    @Test
    public void getDistributedDir() {
        String fileDir = FileUtils.getDistDir(sAbilityDelegator.getAppContext());
        assertTrue("fileDir is not  null", !fileDir.isEmpty());
    }

    @Test
    public void getRawFile() {
        try {
            final InputStream inputStream = FileUtils.getRawFile(sAbilityDelegator.getAppContext(), "1.jpg");
            assertTrue("inputStream is not  null", inputStream != null);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void getDistDir() {
        String distDir = FileUtils.getDistDir(sAbilityDelegator.getAppContext());
        assertTrue("distDir is not  null", distDir != null);

    }

}